function n_getArgs(args)
{
  var ret = new Object();
  ret.params = new Object();
  ret.objAttrs = new Object();
  for (var i=0; i < args.length; i=i+2){
    var currArg = args[i].toLowerCase();    

    switch (currArg){
      case "elementid":
        ret.id = args[i+1];
        break;
      case "id":
      case "width":
      case "height":
      case "code":
      case "codebase":
        ret.objAttrs[args[i]] = args[i+1];
        break;
      default:
        ret.params[args[i]] = args[i+1];
    }
  }
  return ret;
}

function n_generateObj(objAttrs, params) 
{ 
  var str = '<applet ';
  for (var i in objAttrs)
    str += i + '="' + objAttrs[i] + '" ';
  str += '>';
  for (var i in params)
    str += '<param name="' + i + '" value="' + params[i] + '" /> ';
  str += ' </applet>';

  return str;
}

function n_substituteApplet() 
{
  var ret = n_getArgs(arguments);
  var code = n_generateObj(ret.objAttrs, ret.params);
  var el = document.getElementById(ret.id);
  var applet = el.cloneNode(true);
  applet.innerHTML = code;
  el.parentNode.replaceChild(applet, el);
}

function n_addApplet() 
{
  var ret = n_getArgs(arguments);
  var code = n_generateObj(ret.objAttrs, ret.params);
  document.write(code);
}

function n_generateAppletCode() 
{
  var ret = n_getArgs(arguments);
  var code = n_generateObj(ret.objAttrs, ret.params);
  return code;
}
